Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

http: incoming parser set to null twice causes crash #4948

Closed
wants to merge 2 commits into from

Conversation

hnry
Copy link

@hnry hnry commented Mar 7, 2013

The error:

http.js:423
  this.socket.parser.incoming = null;
                              ^
TypeError: Cannot set property 'incoming' of null
    at IncomingMessage._dump (http.js:423:31)
    at ServerResponse.<anonymous> (http.js:1979:13)
    at ServerResponse.EventEmitter.emit (events.js:91:17)
    at ServerResponse.OutgoingMessage._finish (http.js:963:8)
    at ServerResponse.OutgoingMessage.end (http.js:946:10)
    at IncomingMessage.<anonymous> (###### user code #####)
    at IncomingMessage.EventEmitter.emit (events.js:116:20)
    at _stream_readable.js:852:12
    at process._tickCallback (node.js:403:13)

@hnry
Copy link
Author

hnry commented Mar 7, 2013

it looks like freeParser already sets it to null

Would just checking if it's already been freed/set to null be ok?

@hnry
Copy link
Author

hnry commented Mar 8, 2013

By the way this is how to reproduce:

var http = require('http');
http.createServer(function(serverReq, serverRes){
  http.request({hostname: 'google.com', port: 80}, function(res) {
    res.on('data', function(data) { }); // this is required to reproduce
    serverRes.end(); // this is required this to reproduce
  }).end();
}).listen(8080);

Send a request to the server listening on 8080 and close the connection early.

The two required pieces of line to reproduce I'm guessing one is calling freeParser() and the other is calling _dump(). So this.socket.parser gets set to null twice.

@bnoordhuis
Copy link
Member

Can you add a regression test in test/simple or test/internet? (One that preferably doesn't need external services.)

Also, please see https://github.com/joyent/node/blob/master/CONTRIBUTING.md - esp. the bits about the CLA and the commit log.

Fix nodejs#4948

This adds a check before setting the incoming parser
to null. Under certain circumstances it'll already be set to
null by freeParser().

Otherwise this will cause node to crash as it tries to set
null on something that is already null.
res.on('data', function(data) {});
}).end();

}).listen(8080);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be common.PORT

@hnry
Copy link
Author

hnry commented Mar 8, 2013

No it doesn't need to contact an external site, it can make a request to the created server. I just thought it would help clarify use case.

I can make the changes, but I noticed a lot of tests related to http are failing because of this bug. Should I include the test still?

[Update] Actually I'm going to include it, most of the tests that are failing due to this bug do not fail when running with node v0.9.12 (only v0.9.13-pre), my test fails for both

@isaacs isaacs closed this in 9f4c3b0 Mar 8, 2013
@isaacs
Copy link

isaacs commented Mar 8, 2013

Thanks! Landed on 9f4c3b0.

@isaacs
Copy link

isaacs commented Mar 8, 2013

Aaaannnd reverted on 632b7d8. My bad.

This test doesn't pass with the commit, and also makes a bunch of other tests fail.

@isaacs isaacs reopened this Mar 8, 2013
var common = require('../common');
var http = require('http');

http.createServer(function(serverReq, serverRes){
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This server listens, but never calls server.close() so the test script will stay open forever and time out.

@hnry
Copy link
Author

hnry commented Mar 9, 2013

Sorry for the oversight

this test crashes as it'll try to set the incoming parser
to null twice
isaacs pushed a commit that referenced this pull request Mar 9, 2013
Fix #4948

This adds a check before setting the incoming parser
to null. Under certain circumstances it'll already be set to
null by freeParser().

Otherwise this will cause node to crash as it tries to set
null on something that is already null.
@isaacs
Copy link

isaacs commented Mar 9, 2013

Landed in v0.10 on 5757ce4. Thanks!

@isaacs isaacs closed this Mar 9, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants